package com.xx.service.Impl;

import com.xx.dao.auctionrecord.AuctionRecordDao;
import com.xx.entity.Auctionrecord;
import com.xx.entity.VO.AuctionRecordVo;
import com.xx.service.AuctionRecordService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @author 许欣
 * 时间：2022/4/15 10:05
 * 描述：
 */
public class AuctionRecordServiceImpl implements AuctionRecordService {
    @Override
    public List<AuctionRecordVo> getAll(Integer auctionId) throws IOException {
        String resource = "mybatis-config.xml";
        InputStream is = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        AuctionRecordDao dao=sqlSession.getMapper(AuctionRecordDao.class);
        //AuctionService dao=new AuctionServiceImpl();
        List<AuctionRecordVo> list=dao.getAll1(auctionId);

        return list;
    }

    @Override
    public List<Auctionrecord> getAllId() throws IOException {
        String resource = "mybatis-config.xml";
        InputStream is = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        AuctionRecordDao dao=sqlSession.getMapper(AuctionRecordDao.class);
        //AuctionService dao=new AuctionServiceImpl();
        List<Auctionrecord> list=dao.getAllId();
        return list;
    }

    @Override
    public int add(Auctionrecord auctionrecord) throws IOException {
        String resource = "mybatis-config.xml";
        InputStream is = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        AuctionRecordDao dao=sqlSession.getMapper(AuctionRecordDao.class);
        int ret=dao.add(auctionrecord);
        sqlSession.commit();
        sqlSession.rollback();
        sqlSession.close();
        return ret;
    }
}
